﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace PVP
{
    class lookup
    {
        public string appPath = string.Empty;
        public string RightPath = string.Empty;
        public string LeftPath = string.Empty;
        public List<string[]> leftList = new List<string[]>();
        public List<string[]> rigthList = new List<string[]>();


        public lookup(string applicationPath)
        {
            appPath = applicationPath;
            RightPath = appPath + "\\data\\RigthGrp";
            LeftPath = appPath + "\\data\\LeftGrp";
            LodaData();
        }

        public void LodaData()
        {
            string[] fn = null;
            fn = Directory.GetFiles(LeftPath);
            for (int i = 0; i < fn.Length; i++)
            {
                using (StreamReader sr = new StreamReader(fn[i]))
                {
                    leftList.Add(sr.ReadToEnd().Split('\n'));
                }
            }
            fn = Directory.GetFiles(RightPath);
            for (int i = 0; i < fn.Length; i++)
            {
                using (StreamReader sr = new StreamReader(fn[i]))
                {
                    rigthList.Add(sr.ReadToEnd().Split('\n'));
                }
            }
        }

        public string[] Next(string kind, int index)
        {

            if (kind == "left" && leftList.Count == 0) return null;
            if (kind == "right" && rigthList.Count == 0) return null;
            if (kind == "left")
            {
                if (index >= leftList.Count)
                {
                    return leftList[leftList.Count - 1];
                }
                if (index <= 0)
                {
                    return leftList[0];
                }
                return leftList[index];
            }
            if (kind == "right")
            {
                if (index >= rigthList.Count)
                {
                    return rigthList[rigthList.Count - 1];
                }
                if (index <= 0)
                {
                    return rigthList[0];
                }
                return rigthList[index];
            }
            return null;
        }
    }
}
